package com.appwoo.txtws.activity;

import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.appwoo.txtws.adapter.WinInTestBookAdapter;
import com.appwoo.txtws.bean.BookBean;
import com.appwoo.txtws.bean.BookSubjectBean;
import com.appwoo.txtws.component.BookHelper;
import com.appwoo.txtws.component.DBHelper;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;

public class WinInTestBookActivity extends BookActivity
  implements View.OnClickListener
{
  private Dialog bookConfirmDialog;
  private Dialog bookDialog;
  private ArrayList<BookBean> books;
  private View.OnClickListener confirmDialogNoOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      WinInTestBookActivity.this.bookConfirmDialog.dismiss();
    }
  };
  private View.OnClickListener confirmDialogRemoveAllYesOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      Iterator localIterator = WinInTestBookActivity.this.books.iterator();
      while (true)
      {
        if (!localIterator.hasNext())
        {
          WinInTestBookActivity.this.books.clear();
          BookSubjectBean localBookSubjectBean = WinInTestBookActivity.this.mDBHelper.getBookSubjectBySubjectId(WinInTestBookActivity.this.currentBookSubject.getSubjectId());
          if ((localBookSubjectBean != null) && (localBookSubjectBean.getDeleteable() == 1) && (localBookSubjectBean.getAscription() != null) && (localBookSubjectBean.getAscription().indexOf("@" + WinInTestBookActivity.this.grade + "@") > -1))
          {
            localBookSubjectBean.setAscription(localBookSubjectBean.getAscription().replace("@" + WinInTestBookActivity.this.grade + "@", ""));
            WinInTestBookActivity.this.mDBHelper.updateBookSubjectBean(localBookSubjectBean);
          }
          WinInTestBookActivity.this.showWinInTestBookList2();
          WinInTestBookActivity.this.bookConfirmDialog.dismiss();
          return;
        }
        BookBean localBookBean = (BookBean)localIterator.next();
        if (localBookBean != null)
        {
          WinInTestBookActivity.this.mDBHelper.removeBookBeanByBookId(localBookBean.getBookId());
          WinInTestBookActivity.this.mBookHelper.deleteAllFile(new File(localBookBean.getLocalPath()));
        }
      }
    }
  };
  private View.OnClickListener confirmDialogYesOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookBean localBookBean = (BookBean)paramAnonymousView.getTag();
      WinInTestBookActivity.this.mDBHelper.removeBookBeanByBookId(localBookBean.getBookId());
      WinInTestBookActivity.this.mBookHelper.deleteAllFile(new File(localBookBean.getLocalPath()));
      WinInTestBookActivity.this.books = WinInTestBookActivity.this.mDBHelper.getBookBeanListBySubjectId(WinInTestBookActivity.this.currentBookSubject.getSubjectId(), WinInTestBookActivity.this.grade);
      if ((WinInTestBookActivity.this.books == null) || (WinInTestBookActivity.this.books.isEmpty()))
      {
        BookSubjectBean localBookSubjectBean = WinInTestBookActivity.this.mDBHelper.getBookSubjectBySubjectId(localBookBean.getSubjectId());
        if ((localBookSubjectBean != null) && (localBookSubjectBean.getDeleteable() == 1) && (localBookSubjectBean.getAscription() != null) && (localBookSubjectBean.getAscription().indexOf("@" + WinInTestBookActivity.this.grade + "@") > -1))
        {
          localBookSubjectBean.setAscription(localBookSubjectBean.getAscription().replace("@" + WinInTestBookActivity.this.grade + "@", ""));
          WinInTestBookActivity.this.mDBHelper.updateBookSubjectBean(localBookSubjectBean);
        }
      }
      WinInTestBookActivity.this.showWinInTestBookList2();
      WinInTestBookActivity.this.bookConfirmDialog.dismiss();
    }
  };
  private BookSubjectBean currentBookSubject;
  private View.OnClickListener dialogCloseOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      WinInTestBookActivity.this.bookDialog.dismiss();
    }
  };
  private View.OnClickListener dialogRemoveAllOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookBean localBookBean = (BookBean)paramAnonymousView.getTag();
      WinInTestBookActivity.this.showConfirmRemoveDialog(localBookBean, false);
    }
  };
  private View.OnClickListener dialogRemoveOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookBean localBookBean = (BookBean)paramAnonymousView.getTag();
      WinInTestBookActivity.this.showConfirmRemoveDialog(localBookBean, true);
    }
  };
  private View.OnClickListener dialogViewOnClickListener = new View.OnClickListener()
  {
    public void onClick(View paramAnonymousView)
    {
      BookBean localBookBean = (BookBean)paramAnonymousView.getTag();
      Intent localIntent = new Intent(WinInTestBookActivity.this, BookReaderQuestionActivity.class);
      localIntent.putExtra("bookname", localBookBean.getName());
      localIntent.putExtra("readerType", "local");
      WinInTestBookActivity.this.startActivity(localIntent);
      WinInTestBookActivity.this.bookDialog.dismiss();
    }
  };
  private DisplayMetrics dm;
  private int firstExtra;
  private int grade;
  private LayoutInflater inflater;
  private int listItemHeight;
  private WinInTestBookAdapter mAdapter;
  private BookHelper mBookHelper;
  private DBHelper mDBHelper;
  private ImageView mIvWinInTestBookBookstore;
  private RelativeLayout mLayoutWinInTestBookHeader;
  private ListView mLvWinInTestBook;
  private TextView mTvWinInTestBookSubject;
  private String subject;

  private void findView()
  {
    this.mLayoutWinInTestBookHeader = ((RelativeLayout)findViewById(2131493658));
    this.mTvWinInTestBookSubject = ((TextView)findViewById(2131493659));
    this.mIvWinInTestBookBookstore = ((ImageView)findViewById(2131493660));
    this.mLvWinInTestBook = ((ListView)findViewById(2131493662));
    this.mBookHelper = new BookHelper();
  }

  private void getListItemHeight()
  {
    this.dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(this.dm);
    int i = this.mLayoutWinInTestBookHeader.getHeight();
    int j = SyncTutorialActivity.getStatusHeight(this);
    int k = this.dm.heightPixels - i - j;
    this.listItemHeight = (k / 7);
    this.firstExtra = (k % 7);
  }

  private void setView()
  {
    this.mDBHelper = new DBHelper(this);
    this.inflater = ((LayoutInflater)getSystemService("layout_inflater"));
    this.mIvWinInTestBookBookstore.setOnClickListener(this);
    this.mLvWinInTestBook.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
    {
      public void onGlobalLayout()
      {
        if (WinInTestBookActivity.this.mAdapter == null)
        {
          WinInTestBookActivity.this.getListItemHeight();
          WinInTestBookActivity.this.mAdapter = new WinInTestBookAdapter(WinInTestBookActivity.this, WinInTestBookActivity.this.books, WinInTestBookActivity.this.listItemHeight, WinInTestBookActivity.this.firstExtra);
          WinInTestBookActivity.this.mLvWinInTestBook.setAdapter(WinInTestBookActivity.this.mAdapter);
        }
      }
    });
    this.subject = getIntent().getStringExtra("subject");
    this.grade = getIntent().getIntExtra("grade", -1);
    if ((this.subject == null) || ("".equals(this.subject)))
    {
      alertMessage(getString(2131428182));
      finish();
    }
    if (this.grade == -1)
    {
      alertMessage(getString(2131428182));
      finish();
    }
    this.currentBookSubject = this.mDBHelper.getBookSubjectBeanByName(this.subject);
    if (this.grade == 18);
    for (String str = "中考" + this.subject; ; str = "高考" + this.subject)
    {
      this.mTvWinInTestBookSubject.setText(str);
      return;
    }
  }

  private void showWinInTestBookList()
  {
    this.books = this.mDBHelper.getBookBeanListBySubjectId(this.currentBookSubject.getSubjectId(), this.grade);
    showWinInTestBookList2();
  }

  private void showWinInTestBookList2()
  {
    while (true)
    {
      if (this.books.size() >= 7)
      {
        if (this.mAdapter != null)
        {
          this.mAdapter.setData(this.books);
          this.mAdapter.notifyDataSetChanged();
        }
        return;
      }
      this.books.add(null);
    }
  }

  protected void backKeyCallBack()
  {
    super.backKeyCallBack();
    finish();
  }

  public void onClick(View paramView)
  {
    switch (paramView.getId())
    {
    default:
      return;
    case 2131493660:
    }
    Intent localIntent = new Intent(this, BookstoreActivity.class);
    localIntent.putExtra("subject", this.currentBookSubject.getName());
    localIntent.putExtra("bookType", 1);
    localIntent.putExtra("grade", this.grade);
    startActivity(localIntent);
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903236);
    findView();
    setView();
  }

  protected void onResume()
  {
    super.onResume();
    showWinInTestBookList();
  }

  public void showConfirmRemoveDialog(BookBean paramBookBean, boolean paramBoolean)
  {
    View localView = this.inflater.inflate(2130903050, null);
    TextView localTextView = (TextView)localView.findViewById(2131492931);
    Button localButton1;
    Button localButton2;
    if (paramBoolean)
    {
      localTextView.setText(getResources().getString(2131428195));
      localButton1 = (Button)localView.findViewById(2131492933);
      localButton2 = (Button)localView.findViewById(2131492934);
      localButton1.setTag(paramBookBean);
      if (!paramBoolean)
        break label187;
      localButton1.setOnClickListener(this.confirmDialogYesOnClickListener);
    }
    while (true)
    {
      localButton2.setOnClickListener(this.confirmDialogNoOnClickListener);
      this.bookConfirmDialog = new Dialog(this, 2131361833);
      this.bookConfirmDialog.addContentView(localView, new LinearLayout.LayoutParams(-2, -2));
      this.bookConfirmDialog.setCanceledOnTouchOutside(true);
      this.bookConfirmDialog.show();
      if ((this.bookDialog != null) && (this.bookDialog.isShowing()))
        this.bookDialog.dismiss();
      return;
      localTextView.setText(getResources().getString(2131428196));
      break;
      label187: localButton1.setOnClickListener(this.confirmDialogRemoveAllYesOnClickListener);
    }
  }

  public void showLongClickDialog(BookBean paramBookBean)
  {
    View localView = this.inflater.inflate(2130903051, null);
    ((ImageView)localView.findViewById(2131492935)).setOnClickListener(this.dialogCloseOnClickListener);
    ((TextView)localView.findViewById(2131492930)).setText(paramBookBean.getName());
    Button localButton1 = (Button)localView.findViewById(2131492936);
    Button localButton2 = (Button)localView.findViewById(2131492937);
    Button localButton3 = (Button)localView.findViewById(2131492938);
    localButton1.setTag(paramBookBean);
    localButton1.setText(getResources().getString(2131428192));
    localButton1.setOnClickListener(this.dialogViewOnClickListener);
    localButton2.setTag(paramBookBean);
    localButton2.setText(getResources().getString(2131427535));
    localButton2.setOnClickListener(this.dialogRemoveOnClickListener);
    localButton3.setTag(paramBookBean);
    localButton3.setText(getResources().getString(2131428193));
    localButton3.setOnClickListener(this.dialogRemoveAllOnClickListener);
    this.bookDialog = new Dialog(this, 2131361833);
    this.bookDialog.addContentView(localView, new LinearLayout.LayoutParams(-2, -2));
    this.bookDialog.setCanceledOnTouchOutside(true);
    this.bookDialog.show();
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.WinInTestBookActivity
 * JD-Core Version:    0.6.2
 */